﻿@{
	ViewBag.Title = "Create";
	Layout = "~/Views/Shared/_LayoutDialog.cshtml";
}
@model OASys.Web.Areas.ModuleExecutive.Models.ModelApplyHolidayCreate
<style type="text/css">
	.table-detail th
	{
		width: 150px;
	}
</style>
<script type="text/javascript">
	$(function () {
		$('#UTApplyHolidayEntity_BeginTime').datetimepicker({
			onClose: function (dateText, inst) {
				var endDateTextBox = $('#SearchEntity_EndTime');
				if (endDateTextBox.val() != '') {
					var testStartDate = new Date(dateText);
					var testEndDate = new Date(endDateTextBox.val());
					if (testStartDate > testEndDate) {
						endDateTextBox.val(dateText);
						$('#UTApplyHolidayEntity_Hours').val(GetDateDiff($('#UTApplyHolidayEntity_BeginTime').val(), $('#UTApplyHolidayEntity_EndTime').val(), "hour"));
					}
				}
			},
			onSelect: function (selectedDateTime) {
				var start = $(this).datetimepicker('getDate');
				$('#UTApplyHolidayEntity_EndTime').datetimepicker('option', 'minDate', new Date(start.getTime()));
			}
		});
		$('#UTApplyHolidayEntity_EndTime').datetimepicker({
			onClose: function (dateText, inst) {
				var startDateTextBox = $('#SearchEntity_BeginTime');
				if (startDateTextBox.val() != '') {
					var testStartDate = new Date(startDateTextBox.val());
					var testEndDate = new Date(dateText);
					if (testStartDate > testEndDate) {
						startDateTextBox.val(dateText);
						$('#UTApplyHolidayEntity_Hours').val(GetDateDiff($('#UTApplyHolidayEntity_BeginTime').val(), $('#UTApplyHolidayEntity_EndTime').val(), "hour"));
					}
				}
			},
			onSelect: function (selectedDateTime) {
				var end = $(this).datetimepicker('getDate');
				$('#UTApplyHolidayEntity_BeginTime').datetimepicker('option', 'maxDate', new Date(end.getTime()));
			}
		});

		$('#UTApplyHolidayEntity_BeginTime,#UTApplyHolidayEntity_EndTime').change(function () {
			if ($('#UTApplyHolidayEntity_BeginTime').val() != "" && $('#UTApplyHolidayEntity_EndTime').val() != "") {
				$('#UTApplyHolidayEntity_Hours').val(GetDateDiff($('#UTApplyHolidayEntity_BeginTime').val(), $('#UTApplyHolidayEntity_EndTime').val(), "hour"));
			}
		});
	});
	/*
	* 获得时间差,时间格式为 年-月-日 小时:分钟:秒 或者 年/月/日 小时：分钟：秒
	* 其中，年月日为全格式，例如 ： 2010-10-12 01:00:00
	* 返回精度为：秒，分，小时，天
	*/
	function GetDateDiff(startTime, endTime, diffType) {
		//将xxxx-xx-xx的时间格式，转换为 xxxx/xx/xx的格式
		startTime = startTime.replace(/\-/g, "/");
		endTime = endTime.replace(/\-/g, "/");
		//将计算间隔类性字符转换为小写
		diffType = diffType.toLowerCase();
		var sTime = new Date(startTime);      //开始时间
		var eTime = new Date(endTime);  //结束时间
		//作为除数的数字
		var divNum = 1;
		switch (diffType) {
			case "second":
				divNum = 1000;
				break;
			case "minute":
				divNum = 1000 * 60;
				break;
			case "hour":
				divNum = 1000 * 3600;
				break;
			case "day":
				divNum = 1000 * 3600 * 24;
				break;
			default:
				break;
		}
		var result = Math.ceil((eTime.getTime() - sTime.getTime()) / parseInt(divNum));
		return result;
	}
</script>
<div class="wfill hfill center">
	<p class="p-s1">
		@(Model.PageState)请假申请
	</p>
	@using (Html.BeginForm())
 {
		@Html.HiddenFor(x => x.UTApplyHolidayEntity.InputDate)
		@Html.HiddenFor(x => x.UTApplyHolidayEntity.InputUser)
		<table cellpadding="0" cellspacing="0" align="center" class="table-detail">
			<thead>
				<tr>
					<td colspan="2">
						<div>
							请假申请</div>
					</td>
				</tr>
			</thead>
			<tbody>
				<tr>
					<th>
						<span class="red">*</span>开始时间：
					</th>
					<td>
						@Html.TextBoxFor(x => x.UTApplyHolidayEntity.BeginTime, new { maxlength = 50 })
						@Html.ValidationMessageFor(x => x.UTApplyHolidayEntity.BeginTime)
					</td>
				</tr>
				<tr>
					<th>
						<span class="red">*</span>结束时间：
					</th>
					<td>
						@Html.TextBoxFor(x => x.UTApplyHolidayEntity.EndTime, new { maxlength = 50 })
						@Html.ValidationMessageFor(x => x.UTApplyHolidayEntity.EndTime)
					</td>
				</tr>
				<tr>
					<th>
						<span class="red">*</span>请假小时数：
					</th>
					<td>
						@Html.TextBoxFor(x => x.UTApplyHolidayEntity.Hours, new { maxlength = 10 })
						@Html.ValidationMessageFor(x => x.UTApplyHolidayEntity.Hours)
					</td>
				</tr>
				<tr>
					<th>
						<span class="red">*</span>请假类型：
					</th>
					<td>
						@Html.DropDownListForFix(x => x.UTApplyHolidayEntity.HolidayType, SelectListHelper.ComposeSelectListFromCollect(Model.ListSysCodeInfo(EnumSysCodeInfoType.HolidayType), x => x.Code, x => x.Name, "-- 请选择 --", null))
						@Html.ValidationMessageFor(x => x.UTApplyHolidayEntity.HolidayType)
					</td>
				</tr>
				<tr>
					<th>
						<span class="red">*</span>请假原因：
					</th>
					<td>
						@Html.TextAreaForFix(x => x.UTApplyHolidayEntity.Remark, new { maxlength = 100, style = "height:120px;width:300px;", cols = "20", rows = "5" })
						@Html.ValidationMessageFor(x => x.UTApplyHolidayEntity.Remark)
					</td>
				</tr>
				<tr>
					<th>
						<span class="red">*</span>审批人：
					</th>
					<td>
						@Html.TextBoxFor(x => x.WFInstanceStatusEntity.AudtingUser, new { style="display:none;"})
						<input type="text" id="auditingUser" />
						<input type="button" value="选择" />
					</td>
				</tr>
			</tbody>
		</table>
		<div class="center wfill">
			@Html.HiddenFor(x => x.UTApplyHolidayEntity.ID)
			<input type="submit" value="保存" class="button" />
			<input type="button" value="关闭" class="button" onclick="javascript:window.parent.closeDialog();" />
		</div>
 }
</div>
